package cn.jingyuan.swan.system.web.controller.gateway;

import cn.jingyuan.bee.exception.SystemExceptionUtils;
import cn.jingyuan.swan.cloud.core.ExCode;
import cn.jingyuan.swan.cloud.core.Result;
import cn.jingyuan.swan.cloud.core.ResultUtils;
import cn.jingyuan.swan.system.service.GatewayService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

@RestController
public class GatewayController {

    @Resource
    GatewayService gatewayService;

    /**
     * 刷新网关
     */
    @ApiOperation(value = "刷新网关", notes = "刷新网关路由")
    @PostMapping(path = "/gateway/refresh", produces = APPLICATION_JSON_VALUE)
    public Result<Void> refreshGateway(@RequestBody Map<String, String> params) {
        String gatewayIServerId = params.get("gatewayIServerId");
        if (null == gatewayIServerId) {
            throw SystemExceptionUtils.newInstance(ExCode.FAILURE);
        }

        gatewayService.refreshGateway(gatewayIServerId);

        return ResultUtils.ok();
    }

}
